/*
 * This class displays the first screen which has options to navigate to the
 * client of the administrative screens
 */

/*
 * LogIn.java
 *
 * Created on 13-Mar-2011, 10:30:35 AM
 */

package pos.ui.screen;

//import pos.ui.screen.administrator.AdministratorConsole;
import java.awt.Toolkit;
import pos.auth.Authentication;
import pos.interfaces.Messages;
import pos.ui.screen.administrator.AdministratorConsole;
import sun.security.acl.PermissionImpl;

/**
 *
 * @author rsrikanth
 */
public class LogIn extends javax.swing.JFrame implements Messages{

    /** Creates new form LogIn */
    public LogIn() {
        setTitle(LOGINTITLE);
        initComponents();
        setIconImage(Toolkit.getDefaultToolkit().getImage("..\\pos\\images\\JavaCup.gif"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        customerBtn = new javax.swing.JButton();
        customerBtn2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        titleLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titleLabel.setText("Welcome - Have a great day!");

        customerBtn.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        customerBtn.setMnemonic('c');
        customerBtn.setText("POS");
        customerBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerBtnActionPerformed(evt);
            }
        });

        customerBtn2.setFont(new java.awt.Font("Tahoma", 0, 24));
        customerBtn2.setMnemonic('a');
        customerBtn2.setText("Adminstrator");
        customerBtn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerBtn2ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setText("DigiShop");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(customerBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(customerBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(139, 139, 139)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(284, 284, 284))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(customerBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(customerBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(77, Short.MAX_VALUE))
        );

        customerBtn.getAccessibleContext().setAccessibleDescription("Click Customer log in button to input customer login credentials");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void customerBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerBtnActionPerformed
        this.setVisible(false);
        Customer customer = new Customer();
        customer.setLoginParent(this);
        customer.setVisible(true);
        
    }//GEN-LAST:event_customerBtnActionPerformed

    private void customerBtn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerBtn2ActionPerformed
//        new AdministratorConsole().setVisible(true);
        String action = "ADMIN_CONSOLE";
        if(!Authentication.isLoggedIn()) {
            Home h1 = new Home(action);
            h1.setVisible(true);
            if(Authentication.hasPermission(new PermissionImpl(action))) {
                h1.dispose();
                new AdministratorConsole().setVisible(true);
            }
        } else {
            if(Authentication.hasPermission(new PermissionImpl(action))) {
                new AdministratorConsole().setVisible(true);
            } else {
                new Logout("However you do not have sufficient previleges for this operation.");
            }
        }
//        String goTo = "ADMIN_CONSOLE";
//        new Home(goTo).setVisible(true);
    }//GEN-LAST:event_customerBtn2ActionPerformed

    /**
    * @param args the command line arguments
    */
    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LogIn().setVisible(true);
            }
        });
    }
     */ 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton customerBtn;
    private javax.swing.JButton customerBtn2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

}
